var t = getApp(), e = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js"), a = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js");

Page({
    data: {
        orderId: null,
        orderData: {},
        orderStatus: null,
        payType: {
            1: "余额支付",
            2: "微信支付",
            3: "微信和余额支付",
            4: "支付宝支付",
            5: "支付宝和余额支付"
        },
        takingType: -1,
        orderProductDetails: {},
        orderLogistic: {},
        orderPrintStatus: null,
        customerStatus: -1,
        isChangeTakingType: !1,
        isGettingAddress: !1,
        isShowCustomer: !1,
        customerData: {},
        deviceMsg: {},
        isDeviceLoading: !1,
        expressType: {
            1: "普通快递",
            2: "当日达"
        }
    },
    onLoad: function(e) {
        var a = this;
        t.globalData.chooseAddressItem = null, this.setData({
            orderId: 1 * e.orderId
        }, function() {
            a.loadOrderDetail(!0);
        });
    },
    onUnload: function() {
        t.globalData.chooseAddressItem = null;
    },
    onShow: function() {
        if (this.data.isGettingAddress) {
            this.setData({
                isGettingAddress: !1
            });
            var e = t.globalData.chooseAddressItem;
            null !== e && this.handleChangeTakingType(1, e.address_id);
        }
    },
    onReady: function() {
        this.payTip = this.selectComponent("#payTip");
    },
    tapCallPhone: function() {
        wx.makePhoneCall({
            phoneNumber: "4008632053"
        });
    },
    tapRefund: function() {
        var a = this;
        wx.showModal({
            title: "是否退款？",
            content: "您可以再考虑看看哦",
            confirmText: "不退款",
            cancelText: "退款",
            success: function(o) {
                o.cancel && (wx.showLoading({
                    mask: !0
                }), e.post("/v2/order/product/refund", {
                    order_id: a.data.orderId
                }).then(function(e) {
                    wx.hideLoading(), 1001 === e.data.code && (t.globalData.isEditOrder = !0, a.loadOrderDetail());
                }).catch(function() {
                    wx.hideLoading();
                }));
            }
        });
    },
    tapPay: function() {
        var t = this.data.orderData;
        0 === t.order_type_taking ? this.payTip.getDeviceMsg({
            orderId: t.order_id,
            price: t.order_total_paid,
            isUpdate: !0
        }) : wx.navigateTo({
            url: "/pages/pay/pay?orderId=" + this.data.orderId + "&price=" + t.order_total_paid
        });
    },
    updateDevice: function(t) {
        this.setData({
            deviceMsg: t.detail.data
        });
    },
    refreshDevice: function() {
        this.getDeviceMsg(!1);
    },
    getDeviceMsg: function(t) {
        var a = this;
        this.data.isDeviceLoading || (this.setData({
            isDeviceLoading: !0
        }), e.post("/v2/order/product/queueInfor", {
            order_id: this.data.orderId
        }).then(function(e) {
            a.setData({
                isDeviceLoading: !1
            }), 1001 === e.data.code && a.setData({
                deviceMsg: e.data.response.data
            }, function() {
                t && a.loadOrderDetail(!1, !1);
            });
        }).catch(function() {
            a.setData({
                isDeviceLoading: !1
            });
        }));
    },
    tapCancel: function() {
        var a = this;
        wx.showModal({
            title: "是否取消订单？",
            content: "您可以再考虑看看哦",
            confirmText: "不取消",
            cancelText: "取消",
            success: function(o) {
                o.cancel && (wx.showLoading({
                    mask: !0
                }), e.post("/v2/order/product/cancel", {
                    order_id: a.data.orderId
                }).then(function(e) {
                    wx.hideLoading(), 1001 === e.data.code && (t.globalData.isEditOrder = !0, a.loadOrderDetail(!1, !1));
                }).catch(function() {
                    wx.hideLoading();
                }));
            }
        });
    },
    tapDelete: function() {
        var a = this;
        wx.showModal({
            title: "是否删除订单？",
            content: "您可以再考虑看看哦",
            confirmText: "不删除",
            cancelText: "删除",
            success: function(o) {
                o.cancel && (wx.showLoading({
                    mask: !0
                }), e.delete("/v2/order/product/delete", {
                    order_id: a.data.orderId
                }).then(function(e) {
                    wx.hideLoading(), 1001 === e.data.code && (t.globalData.isEditOrder = !0, wx.navigateBack({
                        delta: 1
                    }));
                }).catch(function() {
                    wx.hideLoading();
                }));
            }
        });
    },
    loadOrderDetail: function(t, a) {
        var o = this;
        wx.showLoading({
            mask: !0
        }), e.get("/v2/order/product/" + this.data.orderId).then(function(t) {
            if (wx.hideLoading(), 1001 == t.data.code) {
                var e = t.data.response.data;
                o.setData({
                    orderData: e,
                    orderStatus: 1 * e.order_status,
                    orderPrintStatus: 1 * e.order_status_print,
                    orderProductDetails: e.order_product_details || [],
                    orderLogistic: e.order_logistic,
                    takingType: 1 * e.order_type_taking,
                    customerStatus: 1 * e.order_status_customer,
                    customerData: e.order_customer || {}
                }, function() {
                    0 === e.order_type_taking && o.getDeviceMsg(!1);
                });
            }
        }).catch(function() {
            wx.hideLoading();
        });
    },
    tapCallSend: function() {
        wx.showLoading({
            mask: !0
        }), setTimeout(function() {
            wx.hideLoading(), wx.showToast({
                title: "已提醒商家发货",
                icon: "none"
            });
        }, 500);
    },
    tapLogistics: function() {
        wx.navigateTo({
            url: "/pages/order/logistics?orderId=" + this.data.orderId
        });
    },
    tapReceiving: function() {
        var t = this;
        a.completeOrder(this.data.orderId, function() {
            t.loadOrderDetail();
        });
    },
    changeTakingType: function(t) {
        1 === 1 * t.currentTarget.dataset.type ? this.setData({
            isGettingAddress: !0
        }, function() {
            wx.navigateTo({
                url: "/pages/address/index?from=order_detail"
            });
        }) : this.handleChangeTakingType(0);
    },
    handleChangeTakingType: function(a, o) {
        var i = this;
        if (!this.data.isChangeTakingType) {
            this.setData({
                isChangeTakingType: !0
            });
            var d = {
                order_id: this.data.orderId
            };
            1 === a && (d.address_id = o), wx.showLoading(), e.post("/v2/order/product/transition/" + (1 === a ? "online" : "offline"), d).then(function(e) {
                wx.hideLoading(), i.setData({
                    isChangeTakingType: !1
                }), 1001 === e.data.code && (1 === a && (t.globalData.chooseAddressItem = null), 
                i.loadOrderDetail(), t.globalData.isEditOrder = !0);
            }).catch(function() {
                wx.hideLoading(), i.setData({
                    isChangeTakingType: !1
                });
            });
        }
    },
    showCustomerModal: function() {
        this.setData({
            isShowCustomer: !0
        });
    },
    closeCustomerModal: function() {
        this.setData({
            isShowCustomer: !1
        });
    },
    saveQrcode: function() {
        var t = this;
        wx.saveImageToPhotosAlbum({
            filePath: "../../assets/images/customer_qrcode.png",
            complete: function() {
                t.closeCustomerModal();
            }
        });
    },
    copyTradeNO: function(t) {
        wx.setClipboardData({
            data: t.currentTarget.dataset.txt,
            success: function() {
                wx.showToast({
                    title: "复制成功"
                });
            }
        });
    }
});